package cn.rengy.web.framework.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import cn.rengy.tool.core.util._NumberUtils;


public class _Utils{
	
	/*public HttpServletRequest getRequest(){
		return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
	}*/
	public static Map<String,Object> getUpdate(List<Long> curList,List<Object> selectedId){
		Map<String,Object> result=new HashMap<String,Object>();
		//1.查询当前用户角色信息
		if(selectedId!=null) {//已选择权限信息
			if(curList!=null) {
				List<Long> insert=new ArrayList<Long>();
				for(int i=0;i<selectedId.size();i++) {
					Long selectId=_NumberUtils.toLong(selectedId.get(i));
					boolean found=false;
					for(int j=0;j<curList.size();j++) {
						Long curId=curList.get(j);
						if(selectId.equals(curId)) {
							found=true;
							curList.remove(j);
							break;
						}
					}
					if(!found) {
						insert.add(selectId);
					}
				}
				result.put("insert", insert);
				//
				if(curList.size()>0) {
					result.put("delete", curList);
				}
			}else {//当前选择为空
				result.put("insert", selectedId);
			}
			
		}else {//已选择为空
			//delete from sys_role_rel where role_rel_info_id=? and role_id=?
			//删除当前选择
			result.put("delete", selectedId);
		}
		return result;
	}
	
	
	public static String getSmallPicName(String picname){
		String smallname=null;
		if(StringUtils.isNotBlank(picname)){
			String [] ps=picname.split("\\.");
			if(ps.length==2){
				return ps[0]+"-small."+ps[1];
			}
		}
		return smallname;
	}
	
	public static void main(String args[]){
		System.out.println(getSmallPicName("123123123.png"));
	}
	/*public static String getQrcodeByUrl(String url,String urlPrefix){
		Assert.notNull(url, "url must not be null");
		Assert.notNull(urlPrefix, "urlPrefix must not be null");
		String code=url.substring(urlPrefix.length());
		return code;
	}*/
}
